package leetcode1;

import java.util.Arrays;

public class Day3 {

    public static void main(String[] args) {

    }


    //122.买卖股票的最佳时机2
    public int maxProfit(int[] prices) {
        int ret=0;
        int i=0;
        for(int j=1;j<prices.length;j++) {
            if(prices[j] <= prices[j-1] ) {
                ret += prices[j-1] - prices[i];
                i=j;
                continue;
            }
            if(j == prices.length-1) {
                ret += prices[j] - prices[i];
            }
        }
        return ret;
    }
    //122.第二种解法--拆分交易
    public int maxProfit2(int[] prices) {
        int ret=0;
        int i=0;
        for(int j=1;j<prices.length;j++) {
            if(prices[j]>prices[j-1]) {
                ret += (prices[j]-prices[j-1]);
            }
        }
        return ret;
    }


}
